#include "BinaryTree.h"

Stack* init_stack() {
    Stack* stack = (Stack*)malloc(sizeof(Stack));
    stack->top = NULL;
    return stack;
}

int is_empty_stack(Stack* stack) { return stack->top == NULL; }

void push(Stack* stack, TreeNode* data) {
    Node* new_node = create_node(data);
    new_node->next = stack->top;
    stack->top = new_node;
}

TreeNode* pop(Stack* stack) {
    if (is_empty_stack(stack)) {
        printf("pop: Stack is empty.\n");
        return NULL;
    }
    Node* temp = stack->top;
    TreeNode* data = temp->data;
    stack->top = stack->top->next;
    free(temp);
    return data;
}

TreeNode* peek(Stack* stack) {
    if (is_empty_stack(stack)) {
        printf("peek: Stack is empty.\n");
        return NULL;
    }
    return stack->top->data;
}